require([ 'jquery', 'app', 'common', 'validate','pagination', 'bootstrap', 'timepicker', 'dateZh' ], function($, app, common,validate) {

	$('title').text('订单管理');
	var deliverytype = ['','上门提货','自送网点'];
	var iscreditapply = ['否','是'];
	//日期控件
	$('#date-start, #date-end').datetimepicker({
		format : "yyyy-mm-dd hh:ii:ss",
		language : "zh-CN",
		todayBtn : 1,
		autoclose : true,
		todayHighlight : true,
		forceParse : true,
		minuteStep : 10
	}); 

	var totalPages = 0;
	var pageSize = '10';
	var first_load = true;
	var reload = true;

	$(document).ready(function() {
		showOrderByPage(1);
		showLogistics();
	});

	//placeholder兼容ie start
	$(function() {
		if (!placeholderSupport()) { // 判断浏览器是否支持 placeholder
			$('[placeholder]').focus(function() {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
					input.val('');
					input.removeClass('placeholder');
				}
			}).blur(function() {
						var input = $(this);
						if (input.val() == ''
								|| input.val() == input.attr('placeholder')) {
							input.addClass('placeholder');
							input.val(input.attr('placeholder'));
					}
			}).blur();
		};
	});
	function placeholderSupport() {
		return 'placeholder' in document.createElement('input');
	}
	//placeholder兼容ie end

	//清除按钮
	$('.clearBtn').on('click', function() {
		$("input[name='orderid-query']").val('');
		$("input[name='sender-query']").val('');
		$("input[name='receiver-query']").val('');
		$("input[name='logisticsNumber-query']").val('');
		$("input[name='receiverIdnumber-query']").val('');
		$("select[name='abnormalStatus-query']").val('');
		$("select[name='state-query']").val('');
		$("select[name='tradeType-query']").val('');  
		$('.setTableLength').val(10);
		$("#date-start").val('');
		$("#date-end").val('');
	}); 

	$(".setTableLength").change(function() {
		reload = true;
		showOrderByPage(1);
	});

	$(".searchBtn").click(function() {
		reload = true;
		showOrderByPage(1);
	});
	

	
	$.validator.addMethod("isPhone", function(value, element) {
   	    var length = value.length;
   	    return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(17[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value))||/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(value);
   	 }, "手机、电话格式不正确");
	
	/** 添加验证start **/
	$('#addStaffForm').validate({
        rules: {
            'nickname': {
                required: true 
            },
            'loginname': {
                required: true 
            },
            'phone':{ 
            	isPhone:true
            }
        },
        messages: {
        	'nickname': {
     		    required: "请填写姓名" 
     		 },
     		'loginname': {
     		    required: "请填写登录帐号" 
     		 },
     		 'phone': { }
        },
        errorClass: "error",
		success: 'valid',
		unhighlight: function(element, errorClass, validClass) { //验证通过
			$(element).tooltip('destroy').removeClass(errorClass);
		}, 
		errorPlacement: function(label, element) {
			$(element).tooltip('destroy'); /*必需*/
			$(element).attr('title', $(label).text()).tooltip('show');
		},
        onclick: true 
    });
	/** 添加验证end **/
	
	
	/** 清空添加数据 start **/
	 $('.add').click(function(e) {
		 $(".errorMsg").html("");
		 $("#addStaffForm").find("input[name='nickname']").val('');
		 $("#addStaffForm").find("input[name='loginname']").val('');
		 $("#addStaffForm").find("select[name='role']").val('管理员');
		 $("#addStaffForm").find("input[name='phone']").val('');
	 })
	 /** 清空添加数据 end **/
	
	/*添加start **/
	$('#btn_addstaff').click(function(e) {
    	var isValid = addStaffForm.valid();
        if (isValid) {
        	 $.post(ctx+"/staff/savestaff", $('#addStaffForm').serialize(),function (data) {
        		var result = data.result;
 				if(result!=null && result=="noauthority") {
 					common.alert1('你无此权限!');
 					return;
 				}
        		if(data.result!=null && data.result=="againLogin") {
            		$('.commonConfirm').modal('hide');
            		common.alert1("登录过期，请重新登录");
 					setTimeout("location.href = ctx + '/login.html'",1000);
               	}else if(data.result=='success'){
               		$('.modal-staff').modal('hide');
             		$('.mySuccessModal1').modal({show:true,backdrop: 'static', keyboard: false});
         	        common.mySuccessModal1('添加成功!','如需继续添加，请点击返回继续添加', 
         	        		'返回继续添加','前往后台用户列表',
     	        		function () {
     	        			$('.mySuccessModal1').modal('hide');  
     	        			$('.modal-order').modal('hide');  
     	        			showOrderByPage(1);
     	        		},
     	        		function () {
     	        			$('.modal-staff').modal('show');
     	        		});
         	        $("#addStaffForm").find("input[name='nickname']").val('');
         			$("#addStaffForm").find("input[name='loginname']").val('');
         			$("#addStaffForm").find("select[name='role']").val('管理员');
         			$("#addStaffForm").find("input[name='phone']").val('');
             	}else if(data.result=='fail'){
             		$(".errorMsg").html(data.message);
             	}else{
             		$(".errorMsg").html("信息提交错误");
             	}
             },"json"); 
        }  
	});
	/** 添加end **/
	 
	 /** 修改验证start **/
	 $('#updateStaffForm').validate({
         rules: {
             'nickname': {
                 required: true
             },
             'phone':{ 
             	isPhone:true
             }
         },
         messages: {
         	'nickname': {
      		    required: "请填写姓名"
      		 },
      		 'phone': {
      		 }
         },
	        errorClass: "error",
			success: 'valid',
			unhighlight: function(element, errorClass, validClass) { //验证通过
				$(element).tooltip('destroy').removeClass(errorClass);
			}, 
			errorPlacement: function(label, element) {
				$(element).tooltip('destroy'); /*必需*/
				$(element).attr('title', $(label).text()).tooltip('show');
			},
	        onclick: true 
     });
	 /** 修改验证end **/
	 
	 /** 修改start **/
	$("#btn_updatestaff").click(function() {
 	var isValid = updateStaffForm.valid();
     if (isValid) { 	
     	 $.post(ctx+"/staff/updatestaff", $('#updateStaffForm').serialize(),function (data) {
     		var result = data.result;
			if(result!=null && result=="noauthority") {
				common.alert1('你无此权限!');
				return;
			}
     		 if(data.result!=null && data.result=="againLogin") {
    			 $('.commonConfirm').modal('hide');
    			 common.alert1("登录过期，请重新登录");;
				 setTimeout("location.href = ctx + '/login.html'",1000);
             }else if(data.result=='success'){ 
          		 $(".modal-view").modal('hide');
      	         common.mySuccessModal2('修改成功!');
      	         showOrderByPage(1);
          	}else{
          		$(".updateMsg").html(data.message);
          	}
          },"json"); 
     }  
	});
	/** 修改end **/
		
	function showOrderByPage(pageNum) {
		if ($(".all").is(':checked')) {
			$(".all").removeAttr('checked');								
		}	
		$("#dataBody").append(loadingHtml);
		if($('.alert-warning').length>0){
    		$('.alert-warning').remove();
    	}
		//是否受理订单，1未受理，2已受理
		//受理状态包含：1未付款，2已付款
		//已受理包含：3报关中,4已发货,5已完成,6已取消,7报关失败,8售后中,9售后完成
		var acceptStatus = $("#acceptorder-query").val(); 
		var statusArr="";
		console.log("acceptStatus:"+acceptStatus);
		if(acceptStatus == 1){
			statusArr = "1,2";
		}else if(acceptStatus == 2) {
			statusArr = "3,4,5,6,7,8,9";
		}
		$.getJSON(ctx + '/order/showorderbypage', {	
				pageNum : pageNum,
				statusArr: statusArr,
				pageSize : $('.setTableLength').val() || 10,
				startTime : $("#date-start").val(),
				endTime : $("#date-end").val(),
				orderId :　$("input[name='orderid-query']").val(),
				status :　$("select[name='state-query").val(), 
				receiver :　$("input[name='receiver-query']").val(),
				abnormalStatus :　$("select[name='abnormalStatus-query'").val(),
				tradeType :　$("select[name='tradeType-query'").val(),
				logisticsNumber :　$("input[name='logisticsNumber-query']").val(),
				receiverIdnumber :　$("input[name='receiverIdnumber-query']").val(),
			},
			function(data){  
				if($('.loading')){
					$('.loading').remove();
				}
				var sumnum = 0;
				var sumweight = 0.0;
				var sumvalume = 0.0;
				var sumorderfee = 0.0;
				var sumagencyfund = 0.0;
				var result = data.result;
				if(result!=null && result=="noauthority") {
					common.alert1('你无此权限!');
					return;
				}
				var isInterior = $("#isInterior").val(); 
				if(data.result!=null && data.result=="againLogin") {
					common.alert1("登录过期，请重新登录");
						setTimeout("location.href = ctx + '/login.html'",1000);
       			} else if(data.result.length == 0) { 
					$('.table-responsive').append('<div class="alert alert-warning no-result text-center" role="alert">没有找到记录... </div>');
                } else{
       				var datapage = data.result;
					var datalist = datapage.result;
					var totalCount = datapage.totalCount;
					var pageNum = datapage.pageNo;
					var pageSize = datapage.pageSize;
					var totalPages = datapage.totalPages;
					$(".totalCount").html(totalCount);
					$(".totalPages").html(totalPages);
					$(".pageNo").html(pageNum);
                    var tempHtml="";   
                    var currentorderid = $('#orderid').val(); 
                    var currentUtype = $('#currentUtype').val(); 
                    for(var i=0;i<datalist.length;i++){   
                    	var order = datalist[i];
                    	var no = (pageNum-1)*pageSize+i+1;
                    	tempHtml +="<tr data-id='"+order.id+"' data-pageno='" + pageNum + "'>";
                    	tempHtml +="<td><div class='checkbox'><label><input type='checkbox' name='itemCheck' value=" +order.id+ " data-orderid="+order.id+" /></label></div></td>";
                    	tempHtml +="<td>"+no+"</td>";
                    	tempHtml +="<td>"+isnull(order.orderId)+"</td>";
                    	tempHtml +="<td>"+isnull(order.receiver)+"</td>";
                    	tempHtml +="<td>"+isnull(order.receiverMobile)+"</td>";
                    	if(isInterior == 1) {
                    		tempHtml +="<td>"+isnull(order.orderAmount)+"</td>";
                    	}
                    	tempHtml +="<td>"+tradeType(order.tradeType)+"</td>";
                    	tempHtml +="<td>"+isnull(order.status)+"</td>";
                    	tempHtml +="<td>"+paymentType(order.paymentType)+"</td>";
                    	tempHtml +="<td>"+abnormalStatus(order.abnormalStatus)+"</td>";
                    	tempHtml +="<td>"+common.getSmpFormatDate(order.createTime)+"</td>"; 
                		tempHtml +="<td class='noExl'><button type='button' data-toggle='modal' data-target='.modal-edityd' onclick='showOrderInfo(" +order.id+")' class='btn btn-primary btn-xs'>查看</button>&nbsp;</td>";
                    	tempHtml +="</tr>";
                    	sumnum += order.goodsnum;
        				sumweight += order.weight;
        				sumvalume += order.volume;
        				sumorderfee += order.sendfee;
        				sumagencyfund += order.agencyfund;
                    	if($('.alert-warning').length>0){
                    		$('.alert-warning').remove();
                    	}
                    }   
                    /*var sl=parseFloat(sumvalume).toFixed(2);
                    var sf=parseFloat(sumorderfee).toFixed(2);
                    tempHtml +="<tr>" +
                    		"<td style='padding: 6px 5px 3px;'>总计</td>  <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> " +
                    		"<td>"+sumnum+"</td>" +
                    		"<td>"+sumweight+"</td>" +
                    		"<td>"+sl+"</td>" +
                    		"<td></td>" +
                    		"<td>"+sf+"</td>" +
                    		"<td></td> <td></td> <td></td> <td></td>" +
                    		"<td>"+sumagencyfund+"</td>" +
                    		"<td></td> <td></td> <td></td>" +
                    		"</tr>";*/
                    if(datalist.length === 0&&$('.alert-warning').length<=0) { 
						$('.table-responsive').append('<div class="alert alert-warning no-result text-center" role="alert">没有找到记录 </div>');
	                } 
                    $('#dataBody').html(tempHtml);
                   
                    if (reload) {
                    	reload = false;
                    	first_load = true;
    					var initPagination = function() {
    						$("#Pagination").pagination(totalCount, {
    							num_edge_entries : 1, // 边缘页数
    							num_display_entries : 4, // 主体页数
    							callback: pageselectCallback,
    							prev_text : "«",
    							next_text : "»",
    							items_per_page : pageSize, 
    							link_to : 'javascript:void(0);'
    						});
    					}();
    					/**分页e**/
                    }
				} 
			}).fail(function (err) { 
				if($('.loading')){
					$('.loading').remove();
				}
				common.alert('服务器错误！请刷新页面重试或联系管理员',"确定"); 
            });  
	}

	function pageselectCallback(page_index, jq) {
		if (first_load) { //第一次初始化不需要请求
			first_load = false;
			return false;
		}
		pageNum = page_index + 1;
		showOrderByPage(pageNum);
	}
	
	/** 保存售后信息start **/
	$("#btn-add-aftersale").click(function() {
		//仅已付款或已发货订单能进行申请异常操作
//		var status = $('#applyAfterSaleForm').find("input[name='status']").val();
//		if(status == "已付款" || status == "已发货"){
//			$('.modal-sup-detail').modal('hide');
//			common.alert1("不满足申请异常条件"); 
//			return;
//		}
    	var isValid = $("#applyAfterSaleForm").valid();  
        if (isValid) { 	  
        	$('#applyAfterSaleForm').find("input[name='orderId']").val($('#orderDetailForm').find("input[name='id']").val());  
        	 $.post(ctx + '/order/aftersale/save', $('#applyAfterSaleForm').serialize(),function (data) {
          		if(data.result!=null && data.result=="againLogin"){
 	         		$('.commonConfirm').modal('hide');
 	         		common.alert1("登录过期，请重新登录");
 					setTimeout("location.href = ctx + '/login.html'",1000);
             	}else if(data.result=='success'){
             		$('.modal-aftersale-detail').modal('hide'); 
             		common.mySuccessModal2(data.message); 
             		$('#applyAfterSaleForm').find("select[name='causeType']").val("");
            		$('#applyAfterSaleForm').find("input[name='remark']").val("");  
            		$('#applyAfterSaleForm').find("input[name='orderId']").val("");  
            		$('#applyAfterSaleForm').find("input[name='proImg']").val("");	//图片地址
            		$('#applyAfterSaleForm').find(".aftersaleImgUpload").val("");	//图片文件 
            		$('.modal-edityd').modal('hide');
               	}else if(data.result=='fail'){
               		$(".errorMsg").html(data.message);
               	}else{
               		$(".errorMsg").html("信息提交错误");
               	}
               },"json"); 
        }  
	});
	/** 保存售后信息end **/
	//上传售后图片
	$(".aftersaleImgUpload").bind('change', function (e) { 
		imguploadaftersale();
	});
	
	function imguploadaftersale(){  
		var formData = new FormData(); 
		formData.append('file', $('.aftersaleImgUpload')[0].files[0]);
		$.ajax({
			 url: ctx + '/order/aftersale/uploadaftersaleimg',
			 type: 'POST',
			 cache: false, //上传文件不需要缓存
			 data: formData,
			 processData: false, // 告诉jQuery不要去处理发送的数据
			 contentType: false, // 告诉jQuery不要去设置Content-Type请求头
			 success: function (data) {
				 var rs = eval(data); 
				 if(rs.result=="success"){
					 var message = rs.message;
					 console.log("图片地址：" + message); 
					 $("#applyAfterSaleForm").find("input[name='proImg']").val(message);
					 $("#aftersaleImgShow").attr("src", ctx + message); 
				 }else{
					 alert("图片上传失败");
				 }
			 }, error: function (data) {
				 alert("图片上传失败");
			 } 
		},"json");
	}
	
	//上传异常证明图片
	$(".abnormalImgUpload").bind('change', function (e) { 
		imgupload();
	});
	
	function imgupload(){  
		var formData = new FormData(); 
		formData.append('file', $('.abnormalImgUpload')[0].files[0]);
		$.ajax({
			 url: ctx + '/order/uploadabnormalimg',
			 type: 'POST',
			 cache: false, //上传文件不需要缓存
			 data: formData,
			 processData: false, // 告诉jQuery不要去处理发送的数据
			 contentType: false, // 告诉jQuery不要去设置Content-Type请求头
			 success: function (data) {
				 var rs = eval(data); 
				 if(rs.result=="success"){
					 var message = rs.message;
					 console.log("图片地址：" + message); 
					 $("#applyAbnormalForm").find("input[name='imgPath']").val(message);
					 $("#abnormalImgShow").attr("src", ctx + message); 
				 }else{
					 alert("图片上传失败");
				 }
			 }, error: function (data) {
				 alert("图片上传失败");
			 } 
		},"json");
	}
	
	//清空异常信息
	$("#applyAbnormalButton").click(function() { 
		$('#applyAbnormalForm').find("select[name='exceptionType']").val("");
		$('#applyAbnormalForm').find("input[name='remark']").val("");  
		$('#applyAbnormalForm').find("input[name='imgPath']").val("");	//图片地址
		$('#applyAbnormalForm').find(".abnormalImgUpload").val("");	//图片文件 
		$('#applyAbnormalForm').find("input[name='orderId']").val("");  
	});
	
	/** 保存异常申请信息start **/
	$("#btn-add-applyAbnormal").click(function() {
		//仅已付款或已发货订单能进行申请异常操作
		var status = $('#orderDetailForm').find("input[name='status']").val();
		console.log("status"+ status);
//		if(status != "已付款" || status != "已发货"){
//			$('.modal-sup-detail').modal('hide');
//			common.alert1("不满足申请异常条件"); 
//			return;
//		}
    	var isValid = $("#applyAbnormalForm").valid();  
        if (isValid) { 	  
        	$('#applyAbnormalForm').find("input[name='orderId']").val($('#orderDetailForm').find("input[name='id']").val());  
        	 $.post(ctx + '/order/abnormal/save', $('#applyAbnormalForm').serialize(),function (data) {
          		if(data.result!=null && data.result=="againLogin"){
 	         		$('.commonConfirm').modal('hide');
 	         		common.alert1("登录过期，请重新登录");
 					setTimeout("location.href = ctx + '/login.html'",1000);
             	}else if(data.result=='success'){
             		$('.modal-sup-detail').modal('hide'); 
             		common.mySuccessModal2(data.message); 
             		$('#applyAbnormalForm').find("select[name='exceptionType']").val("");
            		$('#applyAbnormalForm').find("input[name='remark']").val("");  
            		$('#applyAbnormalForm').find("input[name='orderId']").val("");  
            		$('#applyAbnormalForm').find("input[name='imgPath']").val("");	//图片地址
            		$('#applyAbnormalForm').find(".abnormalImgUpload").val("");	//图片文件 
            		$('.modal-edityd').modal('hide');
               	}else if(data.result=='fail'){
               		$(".errorMsg").html(data.message);
               	}else{
               		$(".errorMsg").html("信息提交错误");
               	}
               },"json"); 
        }  
	});
	/** 保存异常申请信息end **/
	
	/*显示所有快递公司s*/
	function showLogistics(){
		 $.post(ctx+"/logistics/list", {},function (data) {
			var result = data.result;
			if(result!=null && result=="noauthority") {
				common.alert1('你无此权限!');
				return;
			}
     		if(data.result!=null && data.result=="againLogin") {
         		$('.commonConfirm').modal('hide');
     			common.alert1("登录过期，请重新登录");
				setTimeout("location.href = ctx + '/login.html'",1000);
        	}else{
        		var datalist = data.logistics;
        		var tempHtml = "";
        		for(var i=0;i<datalist.length;i++){   
                	var log = datalist[i];
                	tempHtml += "<option value='"+log.id+"'>"+log.logisticsName+"</option>";
                }
      	        $("#deliveryForm").find("select[name='logisticsId']").append(tempHtml); 
          	}
          },"json");
	}
	/*显示所有快递公司e*/
	
	/** 保存发货信息start **/
	$("#btn-delivery-sub").click(function() { 
		//仅已付款订单能进行发货操作
		var status = $('#orderDetailForm').find("input[name='status']").val();
		console.log("status:"+status);
//		if(status != "已付款"){
//			$('.modal-delivery').modal('hide'); 
//			common.alert1("仅限已付款订单能发货");  
//			return;
//		}
		
    	var isValid = $("#deliveryForm").valid();  
        if (isValid) { 	  
        	$('#deliveryForm').find("input[name='id']").val($('#orderDetailForm').find("input[name='id']").val());  
        	 $.post(ctx + '/order/logistics/save', $('#deliveryForm').serialize(),function (data) {
          		if(data.result!=null && data.result=="againLogin"){
 	         		$('.commonConfirm').modal('hide');
 	         		common.alert1("登录过期，请重新登录");
 					setTimeout("location.href = ctx + '/login.html'",1000);
             	}else if(data.result=='success'){
             		$('.modal-delivery').modal('hide'); 
             		common.mySuccessModal2(data.message);  
            		$('#applyAbnormalForm').find("input[name='logisticsNumber']").val("");   
            		$('.modal-edityd').modal('hide');
               	}else if(data.result=='fail'){
               		$(".errorMsg").html(data.message);
               	}else{
               		$(".errorMsg").html("信息提交错误");
               	}
               },"json"); 
        }  
	});
	/** 保存发货信息end **/
	
	/**受理订单多个s*/
	$('#acceptMany').click(function(e) {
		var ids = "";
		var count = 0;
		var checks = document.getElementsByName("itemCheck"); 
		for(var i=0;i<checks.length;i++){
			if(checks[i].checked){
				count++;
				ids += checks[i].value + ",";
			}
		}
		if(count<1){
			common.alert1("请至少选择一个");
		}else{
			$('.commonConfirm').modal('show');
			common.commonConfirm("受理订单", "确定受理", "这"+count+"个订单吗",
				function() {
	            	 $.post(ctx+"/order/accept", {orderIds:ids},
	            		function (data) {
		            		 var result = data.result;
		     				 if(result!=null && result=="noauthority") {
		     					 common.alert1('你无此权限!');
		     					 return;
		     				 }
	    		    		 if(data.result!=null && data.result=="againLogin") {
	    		    			 $('.commonConfirm').modal('hide');
	    		    			 common.alert1("登录过期，请重新登录");
	    						 setTimeout("location.href = ctx + '/login.html'",1000);
	    		             }else if(data.result=='success'){ 
	    		         		 $(".commonConfirm").modal('hide');
	    		     	         common.mySuccessModal2(data.message);
	    		     	        showOrderByPage(1);
	    		         	}else{
	    		         		$(".updateMsg").html(data.message);
	    		         	}
	    		 },"json"); 
			});
		}
	});
	/**受理订单多个e*/

	function isnull(value) {
		if (value == null || value == '' || typeof (value) == "undefined" || value == '/')
			return "--";
		else
			return value;
	}
	
	/*贸易类型，1保税直供，2国内发货，3海外直邮，4海外交货*/
	function tradeType(value) {
		if (value == null || value == ''){
			return "未知";
		}else if(value == 1) {
			return "保税直供";
		}else if(value == 2) {
			return "国内发货";
		} else if(value == 3) {
			return "海外直邮";
		} else if(value == 4) {
			return "海外交货";
		} 
	}
	
	
	/*订单异常状态，1正常，2异常*/
	function abnormalStatus(value) {
		if (value == null || value == ''){
			return "未知";
		}else if(value == 1) {
			return "正常";
		}else if(value == 2) {
			return "异常";
		}
	}
	
	/*支付方式，1微信，2支付宝，3刷卡，4线下支付*/
	function paymentType(value) {
		if (value == null || value == ''){
			return "未知";
		}else if(value == 1) {
			return "微信";
		}else if(value == 2) {
			return "支付宝";
		} else if(value == 3) {
			return "刷卡";
		} else if(value == 4) {
			return "线下支付";
		} else if(value == 5) {
			return "系统预付款";
		} 
	}

	function isnumber(value) {
		if (value == null || value == '')
			return "0.00";
		else
			return value;
	}
});

function showOrderInfo(id){ 
	$.getJSON(ctx + '/order/showorderinfo', {
		id : id
	}, function(data) {
		var order = data.order;
		var productList = data.orderProductList;
		if(data != null){ 
			$(".modal-edityd").find("input[name='id']").val(order.id);
			$(".modal-edityd").find("input[name='orderId']").val(order.orderId);
			$(".modal-edityd").find("select[name='tradeType']").val(order.tradeType);
			$(".modal-edityd").find("input[name='status']").val(order.status);
			$(".modal-edityd").find("input[name='createTime']").val(getFormatDate(order.createTime));
			$(".modal-edityd").find("input[name='paymentTime']").val(getFormatDate(order.paymentTime));
			$(".modal-edityd").find("select[name='paymentType']").val(order.paymentType);
			$(".modal-edityd").find("input[name='receiver']").val(order.receiver);
			$(".modal-edityd").find("input[name='receiverMobile']").val(order.receiverMobile);
			$(".modal-edityd").find("input[name='receiverIdnumber']").val(order.receiverIdnumber);
			$(".modal-edityd").find("input[name='receiverPcdt']").val(order.receiverPcdt);
			$(".modal-edityd").find("input[name='logisticsName']").val(order.logisticsName);
			$(".modal-edityd").find("input[name='logisticsNumber']").val(order.logisticsNumber);
			$(".modal-edityd").find("input[name='deliveryTime']").val(getFormatDate(order.deliveryTime));
			$(".modal-edityd").find("input[name='orderRemark']").val(order.orderRemark);
			$(".modal-edityd").find("input[name='merchantRemark']").val(order.merchantRemark); 
			
			var tempHtml = "";
			var productTotal = 0;
			for(var i=0;i<productList.length;i++){   
            	var product = productList[i]; 
            	var unitPriceTemp = 0;
            	if(product.unitPrice != null){
            		unitPriceTemp = product.unitPrice;
            	}
            	tempHtml +="<tr>";  
            	tempHtml +="<td>"+(product.code)+"</td>";
            	tempHtml +="<td>"+(product.productName)+"</td>";
            	tempHtml +="<td>"+(product.dateValue)+"</td>"; 
            	tempHtml +="<td>"+(product.num)+"</td>";
            	tempHtml +="<td>"+(product.specificationNumber) +  product.packType + "装</td>";
            	tempHtml +="<td>￥"+(unitPriceTemp).toFixed(2);+"</td>";
            	tempHtml +="<td>￥"+(unitPriceTemp * product.num).toFixed(2);+"</td>"; 
        		tempHtml +="</tr>";  
        		productTotal += (unitPriceTemp * product.num);
            }   
			tempHtml +="<tr><td></td><td></td><td></td><td></td><td></td><td colspan='2'>供货价总计：￥"+productTotal.toFixed(2)+"</td></tr>";
			tempHtml +="<tr><td></td><td></td><td></td><td></td><td></td><td colspan='2'>运费：￥"+(order.freight).toFixed(2)+"</td></tr>";
			/*tempHtml +="<tr><td></td><td></td><td></td><td></td><td></td><td colspan='2'>订单金额：￥"+(order.orderAmount).toFixed(2)+"</td></tr>";*/
			
			$('#orderDetailDataBody').html(tempHtml); 
		}else{
			alert("查询失败");
		}
	});
}

/*支付方式，1微信，2支付宝，3刷卡，4线下支付*/
function paymentType(value) {
	if (value == null || value == ''){
		return "未知";
	}else if(value == 1) {
		return "微信";
	}else if(value == 2) {
		return "支付宝";
	} else if(value == 3) {
		return "刷卡";
	} else if(value == 4) {
		return "线下支付";
	} else if(value == 5) {
		return "系统预付款";
	} 
}

function getFormatDate(time, format){
	format = "yyyy-MM-dd HH:mm:ss";
	if(time==null || time=="") {
		return "--";
	}
	var t = new Date(time);
	var tf = function(i){
		return (i < 10 ? '0' : '') + i
	};
	return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
		switch(a){
			case 'yyyy':
				return tf(t.getFullYear());
				break;
			case 'MM':
				return tf(t.getMonth() + 1);
				break;
			case 'mm':
				return tf(t.getMinutes());
				break;
			case 'dd':
				return tf(t.getDate());
				break;
			case 'HH':
				return tf(t.getHours());
				break;
			case 'ss':
				return tf(t.getSeconds());
				break;
		};
	});
};




